package wishes;

import java.util.HashMap;

import enums.WishType;
import model.Model;
import interfaces.AbstractWish;

public class WishToSleep extends AbstractWish {

	private HashMap<String, Integer> clothes;
	private long timeToSleep;

	public WishToSleep(long startTime, long timeToSleep) {
		super(startTime);
		this.timeToSleep = timeToSleep;
		clothes = new HashMap<String, Integer>();
		clothes.put(Model.KLEIDUNG_NACHTHEMD, 1);
		clothes.put(Model.KLEIDUNG_KLEID, 1);
	}

	public boolean canBeFulfilled() {
		return Model.getInstance().getCLothes().contains(clothes);
	}

	public boolean fulfill() {
		if (canBeFulfilled()) {
			Model.getInstance().sleep(timeToSleep);
			Model.getInstance().getWishes().remove(this);
			return true;
		}
		return false;
	}

	public long getTimeToSleep() {
		return timeToSleep;
	}

	public long getDeadLine() {
		return getStartTime() + Model.ZEIT_STUNDE;
	}

	@Override
	public WishType getType() {
		return WishType.WishToSleep;
	}

	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("bis ").append(Model.millisToString(getDeadLine()));
		builder.append(" >> Will schlafen ");	
		builder.append(timeToSleep == Model.SCHLAFEN_KURZ ?  "(kurz)" : "" );
		return builder.toString();
	}
}
